package com.ymatou.iapi.sellertrading.testcase;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.sellertrading.service.BatchApplyForPostpayCall;
import com.ymatou.operate.trading.api.parameter.BatchApplyForPostPayBean;
import com.ymatou.operate.trading.api.service.BatchApplyForPostPayCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.common.entitie.ApplyPostPayInfo;
import com.ymttest.database.model.YmtOrders;
import com.ymttest.database.sqlwapper.YmtOrdersIMapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.constant.ECode;

public class Ts_BatchApplyForPostpay {
	private static BatchApplyForPostPayBean bafppbean;
    private static BatchApplyForPostPayCall bafppcall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("批量订单申请补款");
	}

	@Before
	public void caseUp() {
		bafppbean = new BatchApplyForPostPayBean();
        bafppcall = new BatchApplyForPostPayCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(new BatchApplyForPostpayCall().getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BatchApplyForPostpay_001() {
		Logger.start(true, "卖家申请补款成功");
		try {
			 Logger.comment("前置数据准备");
	         int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
	         List<YmtOrders> list  = new YmtOrdersIMapper().selectbySellerId(sellerId);
	         ArrayList<ApplyPostPayInfo> list1 = new ArrayList<ApplyPostPayInfo>();
			 for (int i = 0; i < 2; i++) {
			   int orderId = list.get(i).getIorderid();
			    // 补款参数
			   ApplyPostPayInfo info = new ApplyPostPayInfo();
			   // 补款理由
			   info.setApplyReason("自动化测试"+i+"次");
			   // 订单ID
			   info.setOrderId(orderId);
			   // 支付金额
			   BigDecimal PayAmount = new BigDecimal(10);
			   info.setPostPayAmount(PayAmount);
			   // 补款类型
			   info.setPostPayType(2);
			   // 买家ID
			   info.setSellerId(sellerId);
			   list1.add(info);
			}
			 Logger.comment("前置数据准备结束");
			 bafppbean.setApplyPostPayInfoList(list1);
			 // 发送请求
			 bafppcall.setData(bafppbean);
			 bafppcall.callService();
			 Logger.verifyEquals(ECode.SUCCESS, bafppcall.getCode(), "验证Code");
			 Logger.verifyEquals(true, bafppcall.getPostPayResultList().get(0).getIsSuccess(), "验证第一条补款是否成功");
			 Logger.verifyEquals(true, bafppcall.getPostPayResultList().get(1).getIsSuccess(), "验证第二条补款是否成功");
            // 数据库验证
           // verifyDb(userId);
		} catch (Exception e) {
			 Logger.fail(e);
		}
	}
	
	
}
